__author__ = 'yejinlei_cn@qq.com'

class pySingleton:
    ''' Singleton  '''

    def __new__(cls, *args, **kwargs):
        '''if Singleton has not _instance attr, create father class object and save it
           else return Singleton's _instance which you create before.

        :rtype: Singleton's _instance attr
        '''
        if not hasattr(cls, '_instance'):
            father = super()
            cls._instance = father.__new__(cls, *args, **kwargs)

        return cls._instance

#test
class TEST(pySingleton):
    def __init__(self): var = 0

if __name__ == '__main__':
    t1 = TEST()
    t2 = TEST()
    t1.var = 10
    print(t2.var)
    print(t1)
    print(t2)
